using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using Objects;
using BAL;

public partial class Customer_UCControls_UCMaThanhToan : System.Web.UI.UserControl
{

    public static List<DangKy> ListDangKy = new List<DangKy>();
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string MaThanhToan = "";
            ListDangKy = (List<DangKy>)Session["ListDangKy"];

            for (int i = 0; i < ListDangKy.Count; i++)
            {
                string TempMaThanhToan = "";
                DangKy ItemDangKy = ListDangKy[i];
                do
                {
                    TempMaThanhToan = RandomMaThanhToan();
                    DangKy ItemMaDangKy = BAL.BALDangKy.GetByMaThanhToan(TempMaThanhToan);
                } while (ItemDangKy.MaThanhToan != "");

                BAL.BALDangKy.Update_MaThanhToan(ItemDangKy);

                if (i == 0)
                    MaThanhToan = TempMaThanhToan;
                else
                    MaThanhToan += "-" + TempMaThanhToan;
            }

            lblMaThanhToan.Text = MaThanhToan;
        }
    }

    public static string RandomMaThanhToan()
    {
        // Generate random text
        string s = "";
        char[] chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".ToCharArray();
        int index;
        int lenght = CaptchaDotNet2.Security.Cryptography.RNG.Next(4, 6);
        for (int i = 0; i < lenght; i++)
        {
            index = CaptchaDotNet2.Security.Cryptography.RNG.Next(chars.Length - 1);
            s += chars[index].ToString();
        }
        return s;
    }
}
